package com.eagle.core.aop;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;
import java.util.List;

/**
 * 代理管理器
 */
public class SelfProxyFactory {
	/**
	 * 输入一个目标类和一组Proxy接口实现, 输出一个代理对象
	 */
	public static <T>T createProxy(final Class<?> targetClass, final List<SelfProxy> proxyList){
		return (T) Enhancer.create(targetClass, new MethodInterceptor() {
			@Override
			public Object intercept(Object targetObject, Method targetMethod,
									Object[] methodParams, MethodProxy methodProxy) throws Throwable {
				return new SelfProxyChain(targetObject, targetMethod, methodProxy, methodParams, proxyList).doProxyChain();
			}
		});
	}
}
